package com.datang.litejvm.constant;

import com.datang.litejvm.print.Visitor;

public class ConstantClassInfo extends ConstantInfo {
    private int tag = ConstantInfo.CONSTANT_CLASS_INFO;
    private String value = "Class";
    private int nameIndex;

    public ConstantClassInfo(ConstantPool pool) {
        super(pool);
    }

    public int getTag() {
        return tag;
    }

    public int getNameIndex() {
        return nameIndex;
    }

    public void setNameIndex(int nameIndex) {
        this.nameIndex = nameIndex;
    }

    @Override
    public String getValue() {
        return value;
    }

    /**
     * @author: 顶风少年
     * @Description: 到常量池中查询类名
     * @date: 18:46 2022/6/16
     **/
    public String getClassName() {
        ConstantUTF8Info utf8Info = (ConstantUTF8Info)constantPool.getConstantInfo(nameIndex);
        return utf8Info.getBytes();
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }
}
